#! /bin/groovy
pipeline{
    agent any
    environment {
        SERVER_IP='10.28.151.204'
        SERVER_USER='tpbbops'
        REMOTE_DIR='/data/jars/e-manager-service'
        DEPLOY_DIR='~/e-manager-service'
        SCRIPT_NAME='deploy.yml'
        SRC_FILE='target/tpbb-e-manager-service.jar'
        GIT_URL='git@10.28.151.136:tpbb/tpbb-e-manager-service.git'
    }
    stages{
        stage('\u27BD Checkout'){
            steps{
                echo "checkout gitlab branch:$BRANCH profile:$PROFILE"
                checkout([$class: 'GitSCM', branches: [[name: "$BRANCH"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '72bc744e-7b81-4eca-af37-2314ac8c75e0', url: "$GIT_URL"]]])
            }
        }
        stage('\u27BD Build'){
            steps{
                echo 'building'
                sh "mvn clean package -P $PROFILE -Dmaven.test.skip -U"
            }
        }
        stage('\u27BD Parallel stage'){
            parallel{
                stage('\u2600 Deploy $PROFILE'){
                    steps{
                        echo "$PROFILE deploy start"
                        sh "scp $SRC_FILE $SERVER_USER@$SERVER_IP:$REMOTE_DIR"
                        sh "ssh $SERVER_USER@$SERVER_IP 'cd $REMOTE_DIR&&ansible-playbook $SCRIPT_NAME -f 4'"
                    }
                }
            }

        }
    }
}
